﻿<Window x:Class="KerbalEdit.Views.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:KerbalEdit"
        xmlns:vm="clr-namespace:KerbalEdit.ViewModels"
        xmlns:c="clr-namespace:KerbalEdit.Views.Converters"
        Title="KerbalEdit - Take control of your KSP Data" Height="768" Width="1360">
    <Window.Resources>
        <c:IsDirtyFontStyleConverter x:Key="isDirtyFontStyleConverter" /> 
        <c:ChangedItemBackgroundConverter x:Key="changedItemBackgroundConverter" />
        <HierarchicalDataTemplate x:Key="storableObjectsTemplate"
                                  ItemsSource="{Binding Path=Children}">
            <TextBlock Text="{Binding Path=DisplayName}">
            </TextBlock>
        </HierarchicalDataTemplate>
    </Window.Resources>
    <Grid Name="workspace">
        <TextBox HorizontalAlignment="Left" Height="28" Margin="10,10,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="999" Text="{Binding Path=InstallPath}" />
        <Button Content="Load" HorizontalAlignment="Left" Margin="1062,10,0,0" VerticalAlignment="Top" Width="35"/>
        <Button Content="Folder" HorizontalAlignment="Left" Margin="1014,10,0,0" VerticalAlignment="Top" Width="43" Command="{Binding Path=OpenKspInstallFolderCommand}" />
        <TreeView ItemsSource="{Binding Path=Data.Objects}" HorizontalAlignment="Left" Height="685" Margin="10,43,0,0" VerticalAlignment="Top" Width="447"
                  ItemTemplate="{StaticResource storableObjectsTemplate}">
            <TreeView.ItemContainerStyle>
                <Style TargetType="{x:Type TreeViewItem}">
                    <EventSetter Event="PreviewMouseRightButtonDown" Handler="TreeViewItem_PreviewMouseRightButtonDown" />
                    <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
                    <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
                    <Setter Property="FontStyle" Value="{Binding IsDirty, Converter={StaticResource isDirtyFontStyleConverter}}" />
                    <Setter Property="Background" Value="{Binding IsDirty, Converter={StaticResource changedItemBackgroundConverter}}" />
                    <Setter Property="FontWeight" Value="Normal" />
                    <Style.Triggers>
                        <Trigger Property="IsSelected" Value="True">
                            <Setter Property="FontWeight" Value="Bold" />
                        </Trigger>                     
                    </Style.Triggers>
                </Style>
            </TreeView.ItemContainerStyle>
        </TreeView>
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <DataGrid Name="mappedProps" Grid.Row="1" Grid.Column="0" Margin="467,48,10,378" HorizontalAlignment="Stretch"
                            AutoGenerateColumns="False" IsSynchronizedWithCurrentItem="True" 
                            ItemsSource="{Binding Path=Data.SelectedItem.MappedProperties}">
                <DataGrid.RowStyle>
                    <Style TargetType="{x:Type DataGridRow}">
                        <Setter Property="FontStyle" Value="{Binding IsDirty, Mode=TwoWay, Converter={StaticResource isDirtyFontStyleConverter}}" />
                        <Setter Property="Background" Value="{Binding IsDirty, Mode=TwoWay, Converter={StaticResource changedItemBackgroundConverter}}" />
                        <Setter Property="FontWeight" Value="Normal" />
                    </Style>
                </DataGrid.RowStyle>
                <DataGrid.Columns>
                    <DataGridTextColumn Header="Name" Binding="{Binding Path=Name}" MinWidth="150" IsReadOnly="True">
                    </DataGridTextColumn>
                    <DataGridTextColumn Header="Value" Binding="{Binding Path=Value, Mode=TwoWay}" MinWidth="700">
                    </DataGridTextColumn>
                </DataGrid.Columns>
            </DataGrid>
        </Grid>        
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <DataGrid Name="unmappedProps" Grid.Row="1" Grid.Column="0" Margin="467,373,10,10" HorizontalAlignment="Stretch"
                            AutoGenerateColumns="False" IsSynchronizedWithCurrentItem="True" 
                            ItemsSource="{Binding Path=Data.SelectedItem.UnmappedProperties}">
                <DataGrid.RowStyle>
                    <Style TargetType="{x:Type DataGridRow}">
                        <Setter Property="FontStyle" Value="{Binding IsDirty, Mode=TwoWay, Converter={StaticResource isDirtyFontStyleConverter}}" />
                        <Setter Property="Background" Value="{Binding IsDirty, Mode=TwoWay, Converter={StaticResource changedItemBackgroundConverter}}" />
                        <Setter Property="FontWeight" Value="Normal" />
                    </Style>
                </DataGrid.RowStyle>                
                <DataGrid.Columns>
                    <DataGridTextColumn Header="Key" Binding="{Binding Path=Key, Mode=TwoWay}" MinWidth="150">
                    </DataGridTextColumn>
                    <DataGridTextColumn Header="Value" Binding="{Binding Path=Value, Mode=TwoWay}" MinWidth="700">
                    </DataGridTextColumn>
                </DataGrid.Columns>
            </DataGrid>
        </Grid>
    </Grid>
</Window>
